﻿Chenxin.UI.userManager = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/userMgr.ashx',
    createGrid: function() {
        return new Chenxin.UI.ExpandGrid({
            actionUrl: this.actionUrl,
            pageSize: 50,
            height: 400,
            id: 'userinfoList',
            baseParam: { op: 'search' },
            renderTo: 'userinfo_table',
            hasCheckBox: false,
            scope: this,
            cellBorder: true,
            columns: {}
        });
    },
    initEvent: function() {
        var _this = this;
        /*
        $('.tr_houselist').live('click', function() {
        $('.tr_houselist,.selected_orgbgcolor').each(function() {
        $(this).removeClass('selected_orgbgcolor');
        });

            $(this).toggleClass('selected_orgbgcolor');
        _this.currentId = this.id;

            //$("#hidSelectedUser").val(this.id);
        });
        $('.tr_houselist').live('mouseover', function() {
        $(this).toggleClass('orgbgcolor');
        });
        $('.tr_houselist').live('mouseout', function() {
        $(this).toggleClass('orgbgcolor');
        });*/

        //检索领域的伸缩
        $(".arrow_1").live("click", function() {
            $("#panel").slideToggle("slow");
            $(this).toggleClass("up_1"); return false;
        });

        //添加员工
        $('#aAddUser').live('click', function() {
            //_this.getdatabyrowid();
            _this.showUserManageAdd();
        });

        //编辑员工
        $("#aEditBaseInfo").live("click", function() {
            //_this.getdatabyrowid();
            _this.showUserManageEdit();
        });

        //档案查看
        $("#aArchives").live("click", function() {
            if (_this.currentId == "") {
                alert("请选择一行后查看档案");
                return;
            }
            window.open("PersonnelFile.aspx?userid=" + _this.currentId);
        });

        //人事变动
        $("#aChgPersonnel").live("click", function() {
            //_this.getdatabyrowid();
            _this.showUserChgPersonnel();
        });

        //职权范围变更
        $("#aEditScope").live("click", function() {
            //_this.getdatabyrowid();
            _this.showUserTerms();
        });

        //虚账号
        $("#aAddVirtual").live("click", function() {
            _this.showUserVirtual();
        });

        //激活账号
        $("#aActivate").live("click", function() {
            if (_this.currentId) {
                _this.del("activate", "是否激活此账户？");
            }
            else
                alert("请选择一行后激活账户");
        });

        //冻结账号
        $("#aFreeze").live("click", function() {
            if (_this.currentId) {
                _this.del("freeze", "是否冻结此账户？");
            }
            else
                alert("请选择一行后冻结账户");
        });

        //职务与职权
        $("#aPosTerms").live("click", function() {
            _this.showUserPosTerms();
        });

        $("#exportExcel").click(function() {
            _this.exportAllData();
        });

        $('#aPasswordReset').click(function() {
            _this.showResetPwdWin();
        });
    },
    /**导出全部
    */
    exportAllData: function() {
        _this = this;
        paramStr = _this.search.getParamJson();
        paramStr.showtype = $("#showtype").val();
        paramStr.op = 'exportdata';
        Chenxin.Msg.Waiting.show();
        Chenxin.Fn.exportToExcelByServer(_this.actionUrl, paramStr, '导出文件');
        //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
        Chenxin.Msg.Waiting.hide();
    },
    /**
    *@description 重置密码
    */
    showResetPwdWin: function() {
        if (!this.autoCheck()) {
            return;
        }

        if (!this.resetPwdWin) {
            this.resetPwdWin = new Chenxin.UI.ResetPwdForm({
                scope: this,
                op: 'resetpwd',
                afterGetFormJson: function(model) {
                    delete model.UserCode;
                    Chenxin.apply(this.resetPwdWin.additionalParam, model);
                    this.resetPwdWin.additionalParam.userid = this.currentId;
                }
            });
            $('#' + this.resetPwdWin.id + '_tr_username').hide();
            $('#' + this.resetPwdWin.id + 'old_usercode').unFormValidator(true);
        }
        if (this.resetPwdWin.show()) {
            this.resetPwdWin.setTitle('重置密码');
            this.resetPwdWin.fitData({ UserCode: this.getUserCode(this.currentId) });
        }
    },
    /**
    *员工添加
    */
    showUserManageAdd: function() {
        var _this = this;

        if (!this.jqmUserManageAddForm) {
            this.jqmUserManageAddForm = new Chenxin.UI.UserManageAddForm({
                scope: _this,
                afterGetFormJson: function(json) {
                    json.Sex = json.input_sex;
                    json.IDType = json.divIDType;
                    json.Education = json.divEducation;
                    this.jqmUserManageAddForm.additionalParam.role = json.role;
                    delete json.role;
                    delete json.divCity;
                    delete json.divCompany;
                    delete json.divBusinessDistrict;
                    delete json.divDepartId;
                    delete json.input_sex;
                    delete json.divIDType;
                    delete json.divEmpLevel;
                    delete json.divEditPosition;
                    delete json.divEducation;

                }

            });
        }

        if (this.jqmUserManageAddForm.show()) {
            this.jqmUserManageAddForm.reset();
            $('#td_role').html('');
        }
    },
    /**
    *员工编辑
    */
    showUserManageEdit: function() {
        var _this = this;

        if (!this.autoSelect()) {
            return;
        }

        if (!this.jqmUserManageEditForm) {
            this.jqmUserManageEditForm = new Chenxin.UI.UserManageEditForm({
                scope: _this,
                beforeFitData: function(data) {
                    if (data.BirthDay) {
                        data.BirthDay = data.BirthDay.substr(0, 10); //生日
                    }
                    if (data.ComeDate) {
                        data.ComeDate = data.ComeDate.substr(0, 10);
                    }
                    if (data.ConBegin) {
                        data.ConBegin = data.ConBegin.substr(0, 10);
                    }
                    if (data.ConEnd) {
                        data.ConEnd = data.ConEnd.substr(0, 10);
                    }
                    if (data.WorkAgeBegin) {
                        data.WorkAgeBegin = data.WorkAgeBegin.substr(0, 10);
                    }

                    data.edit_ed = data.Education; //学历
                    data.edit_papers = data.IDType; //身份证
                    data.editinput_sex = data.Sex; //性别
                    data.editValidate = data.Status; //在职状态

                    this.jqmUserManageEditForm.company.param.fatherid = data.BelongCityId;
                    this.jqmUserManageEditForm.company.reload(data.BelongCompanyId);

                    this.jqmUserManageEditForm.departs.param.fatherid = data.BelongCompanyId;
                    this.jqmUserManageEditForm.departs.reload(data.BelongDepartId);

                    var level = this.jqmUserManageEditForm.findByName('EmpLevel');
                    level.param.companyid = data.CompanyId;
                    level.reload(data.EmpLevel);

                    var position = this.jqmUserManageEditForm.findByName('Position');
                    position.param.companyid = data.CompanyId;
                    position.reload(data.Position);


                    this.currentModel = data;



                },
                afterGetFormJson: function(json) {
                    json.Education = json.edit_ed;
                    json.IDType = json.edit_papers;
                    json.Sex = json.editinput_sex;
                    json.Status = json.editValidate;

                    delete json.edit_ed;
                    delete json.edit_papers;
                    delete json.editinput_sex;
                    delete json.editValidate;
                }
            });
        }

        if (this.jqmUserManageEditForm.show('edit')) {
            Chenxin.Fn.getModel('', 'service/userMgr.ashx', function(model) {
                this.fitData(model);
            }, this.jqmUserManageEditForm, 'GetBaseInfo', { UserId: this.currentId });

            if (!this.jqmUserManageEditForm.permit.edit_permit.editall) {
                this.jqmUserManageEditForm.city.setDisable();
                this.jqmUserManageEditForm.company.setDisable();
                this.jqmUserManageEditForm.departs.setDisable();
                this.jqmUserManageEditForm.findByName('editValidate').attr('disabled', 'disabled');
                this.jqmUserManageEditForm.findByName('Position').setDisable();

            }
        }
    },
    /**
    *人事变动
    */
    showUserChgPersonnel: function() {
        var _this = this;

        if (!this.autoSelect()) {
            return;
        }

        if (!this.jqmUserChgPersonnelForm) {
            this.jqmUserChgPersonnelForm = new Chenxin.UI.UserChgPersonnelForm({
                scope: _this,
                beforeFitData: function(json) {

                    var level = this.jqmUserChgPersonnelForm.findByName('Level');
                    level.param.companyid = json.BelongCompanyId;
                    level.reload();


                    var position = this.jqmUserChgPersonnelForm.findByName('Position');
                    position.param.companyid = json.BelongCompanyId;
                    position.reload();


                    delete json.DepartId;
                    delete json.Position;

                },
                afterGetFormJson: function(json) {
                    if (!json.DepartId) {
                        json.DepartId = '00000000-0000-0000-0000-000000000000';
                    }
                    json.DepartName = this.jqmUserChgPersonnelForm.findByName('DepartId').getText();

                    delete json.UserCode;
                    delete json.UserName;
                }
            });
        }

        _this.jqmUserChgPersonnelForm.op = 'change';
        if (this.jqmUserChgPersonnelForm.show()) {
            Chenxin.Fn.getModel(this.currentId, this.actionUrl, function(model) {
                this.fitData(model);
            }, this.jqmUserChgPersonnelForm, 'GetBaseInfo', { UserId: this.currentId });

            $('#tr_city').hide();
            $('#tr_company').hide();
            $('#tr_businessdistrict').hide();
            $('#tr_depart').hide();
            $('#tr_zd').hide();
            $('#tr_zw').hide();
        }
    },
    /**
    *职权变更
    */
    showUserTerms: function() {
        var _this = this;

        if (!this.autoCheck()) {
            return;
        }

        if (!this.jqmUserTermsForm) {
            this.jqmUserTermsForm = new Chenxin.UI.UserTermsForm({
                scope: this,
                beforeFitData: function(model) {
                    model.TermsUserID = model.UserId;
                    delete model.DepartId;
                    delete model.ComeDate;
                },
                afterDelSucc: function() {
                    this.jqmUserTermsForm.grid.reload({ UserID: this.currentId });
                },
                saveSucc: function() {
                    this.jqmUserTermsForm.grid.reload({ UserID: this.currentId });
                },
                afterGetFormJson: function(json) {
                    delete json.UserCode;
                    //delete json.UserName;
                }
            });
        }

        _this.jqmUserTermsForm.op = 'addterms';
        if (this.jqmUserTermsForm.show()) {
            this.jqmUserTermsForm.grid.reload({ UserId: this.currentId });


            $("#div_TermsShow").hide();
            $("#btn_addUserTerms").hide();
            $("#btn_addshowUserTerms").show();

            Chenxin.Fn.getModel(this.currentId, this.actionUrl, function(model) {
                this.fitData(model);
            }, this.jqmUserTermsForm, 'GetBaseInfo', { UserId: this.currentId });

        }
    },
    /**
    *虚帐号
    */
    showUserVirtual: function() {
        var _this = this;
        if (!this.jqmUserVirtualForm) {
            this.jqmUserVirtualForm = new Chenxin.UI.UserVirtualForm({
                scope: _this
            });
        }
        this.jqmUserVirtualForm.op = 'virtual';
        if (this.jqmUserVirtualForm.show()) {
            this.jqmUserVirtualForm.reset();
        }
    },
    /**
    *职务与职权
    */
    showUserPosTerms: function() {
        var _this = this;
        if (!this.jqmUserPosTermsForm) {
            this.jqmUserPosTermsForm = new Chenxin.UI.UserPosTermsForm();
        }

        if (!_this.jqmUserPosTermsForm.PosTermsGrid) {
            _this.jqmUserPosTermsForm.PosTermsGrid = new Chenxin.UI.Pagination({
                actionUrl: _this.actionUrl,
                id: 'postterms',
                pageSize: 10,
                renderTo: 'posterms_table',
                data: { op: "pageShow", stype: "pt" }
            });
        }

        if (this.jqmUserPosTermsForm.show()) {
            _this.jqmUserPosTermsForm.reset();
            _this.jqmUserPosTermsForm.PosTermsGrid.reload();

        }
    },
    createSearch: function() {
        return new Chenxin.UI.userManagerSearch({
            scope: this
        });
    },
    autoCheck: function() {

        //被选择的行
        if (!this.currentId) {
            alert("请选择一行后进行操作");
            return false;
        }

        if (this.getStatus(this.currentId) == '-1') {
            alert("该员工已离职，不可编辑信息");
            return false;
        }
        return true;
    },
    autoSelect: function() {

        //被选择的行
        if (!this.currentId) {
            alert("请选择一行后进行操作");
            return false;
        }
        return true;
    },
    getStatus: function(id) {
        return $('#' + id + ' dd:last').text();
    },
    getUserCode: function(id) {
        return $('#' + id + ' dd:eq(2)').text();
    },
    getdatabyrowid: function() {
        var _this = this;
        _this.rowdata = {};
        $(".selected_orgbgcolor td").each(function() {
            var colname = $(this).attr("name");
            _this.rowdata[colname] = $(this).text();
        });
        return _this.rowdata;
    },
    initComponent: function() {
        Chenxin.UI.userManager.superclass.initComponent.call(this);
    }
});


/**
*查询面板
*/
Chenxin.UI.userManagerSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'house_search',
    initEvent: function() {
        var _this = this;

        //条件输入框匹配
        //        $("#txtCondition").live("keyup", function() {

        //            var strCondition = encodeURIComponent($("#txtCondition").val());
        //            if (strCondition == "") {
        //                $("#hidConditionType").val("");
        //                $("#hidConditionId").val("");
        //                return false;
        //            }
        //            $.ajax({
        //                type: "POST",
        //                url: "service/userMgr.ashx?op=GetCondition&query=" + strCondition,
        //                dataType: "Json",
        //                success: function(strRet) {
        //                    var jsonRet = eval("(" + strRet + ")");
        //                    if (jsonRet.RetFlg == "SUCCESS") {
        //                        var strHtml = jsonRet.Data;
        //                        $("#dlSearchMatch").html(strHtml);
        //                    } else {
        //                        //后台处理的错误信息
        //                        var strErrMsg = "错误信息：" + jsonRet.Data;
        //                        alert(strErrMsg);
        //                    }
        //                }
        //            });

        //            $("#dlSearchMatch").show();
        //        });
        $("#txtCondition").defText({
            deftxt: '工号/姓名/门店'
        });

        $("#resetbutton").live('click', function() {
            _this.reset();
        });

        //        $("#dlSearchMatch").live("click", function(event) {
        //            if (event.target.tagName == "A") {
        //                var objParent = $(event.target).parent();
        //                $("#txtCondition").val($(objParent).find("input[name='hidNm']").val());
        //                //$("#hidConditionType").val($(objParent).parents("dl:first").find("input[name='hidType']").val());
        //                $("#hidConditionType").val($(objParent).find("input[name='hidType']").val());
        //                $("#hidConditionId").val($(objParent).find("input[name='hidId']").val());
        //            }
        //        });

        //生日模式
        $("#aTypeBorn").live("click", function() {
            var _param = _this.getParamJson();
            _this.scope.grid.baseParam.op = 'birthdaysearch';
            $("#showtype").val("2");
            _this.scope.reloadGrid(_param);
        });

        //详细模式
        $("#aTypePersonnel").live("click", function() {
            var _param = _this.getParamJson();
            _this.scope.grid.baseParam.op = 'detailssearch';
            $("#showtype").val("3");
            _this.scope.reloadGrid(_param);
        });

        //简单模式
        $("#aTypeSimple").live("click", function() {
            var _param = _this.getParamJson();
            _this.scope.grid.baseParam.op = 'simplesearch';
            $("#showtype").val("1");
            _this.scope.reloadGrid(_param);
        });

        $('#btSreachUserInfo').click(function() {
            var _param = _this.scope.search.getParamJson();
            _this.scope.reloadGrid(_param);
        });

        $('.a-qucik-search').click(function() {
            _this.scope.reloadGrid({ quicktype: this.id });
        });

    },
    createComboList: function() {
        var _this = this;

        var combl = new Chenxin.UI.StructComboList({
            tbxWidth: 60,
            companyAfterSelected: function(val) {
                if (val == this.company.defVal) {
                    cmbPosition.clearItems();

                    cmbRole.clearItems();

                } else {
                    cmbRole.param.companyid = val;
                    cmbRole.reload();

                    cmbPosition.param.companyid = val;
                    cmbPosition.reload();
                }
            },
            companyAfterLoadItem: function(items) {
                if (items.length == 1) {
                    cmbRole.param.companyid = items[0].val;
                    cmbRole.reload();

                    cmbPosition.param.companyid = items[0].val;
                    cmbPosition.reload();
                }
            }
        });
        var structs = combl.comboList;

        //状态下拉框属性
        var cmbStatus = new Chenxin.UI.Combo({
            containerId: '#divStatus',
            tbxWidth: 45,
            items: comboCommon.UserStatusType
        });

        //生日
        var cmbBirthday = new Chenxin.UI.Combo({
            containerId: '#divBirthday',
            tbxWidth: 48,
            items: [{ val: '1', txt: '1月' }, { val: '2', txt: '2月' }, { val: '3', txt: '3月' }, { val: '4', txt: '4月' }, { val: '5', txt: '5月' }, { val: '6', txt: '6月' }, { val: '7', txt: '7月' }, { val: '8', txt: '8月' }
            , { val: '9', txt: '9月' }, { val: '10', txt: '10月' }, { val: '11', txt: '11月' }, { val: '12', txt: '12月'}]
        });

        //角色
        var cmbRole = new Chenxin.UI.Combo({
            containerId: '#divRole',
            tbxWidth: 60,
            colWidth: 120,
            actionUrl: 'service/EmployeePermitsList.ashx?op=getrole',
            autoLoad: false,
            hasSearch: true,
            colNum: 3,
            hasPage: true,
            pageSize: 15
        });

        //职务
        var cmbPosition = new Chenxin.UI.ParameterCombo({
            containerId: '#divPosition',
            name: 'Position',
            key: 'System.Position',
            inModelType: 'txt',
            hasSearch: true,
            tbxWidth: 60,
            colWidth: 120,
            required: true,
            autoLoad: false,
            colNum: 3,
            hasPage: true,
            pageSize: 15
        });

        //虚帐号
        var cmbIsVirtual = new Chenxin.UI.Combo({
            containerId: '#divIsVirtual',
            tbxWidth: 48,
            items: comboCommon.IsVirtual
        });

        structs.push(cmbStatus);
        structs.push(cmbRole);
        structs.push(cmbPosition);
        structs.push(cmbIsVirtual);
        structs.push(cmbBirthday);

        return structs;
    },
    initComponent: function() {
        Chenxin.UI.userManagerSearch.superclass.initComponent.call(this);
    }
});

/**
*职务与职权查询面板
*/
Chenxin.UI.PosTermsSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'jqmPosTerms',
    initEvent: function() {
        var _this = this;
    },
    initComponent: function() {
        Chenxin.UI.PosTermsSearch.superclass.initComponent.call(this);
    }
});

/**
*用户添加
*/
Chenxin.UI.UserManageAddForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/userMgr.ashx',
    id: 'jqmAddUserInfo',
    renderTo: 'divjqmAddUserInfo',
    title: '人员添加',
    jqmWidth: 700,
    autoAlertSucc: false,
    initFormValidator: function() {
        var _this = this;
        //用户名验证
        $("#UserName").formValidator({ validatorgroup: this.id,
            onshow: "请输入用户名！", onfocus: "请输入用户名", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "用户名不能为空!" }, onerror: "用户名不能为空!"
        });
        //手机号验证
        $("#Mobile").functionValidator({ validatorgroup: this.id,
            fun: function(val, elem) { return val.isMobile(); }, onerror: "请输入正确的手机号"
        });

        //身份证号码验证
        $("#IDNo").formValidator({ validatorgroup: this.id,
            onshow: "请输入证件号", onfocus: "请输入证件号", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {

                if (_this.cmbIDType.getValue() == _this.cmbIDType.defVal) {
                    return '请先选择证件类型';
                } else {
                    if (_this.cmbIDType.getText() == '身份证') {
                        if (val.isIdCardNo()) {
                            $("#BirthDay").val(_this.getBirthday(val));
                        }
                        return val.isIdCardNo();
                    } else {
                        return !val.isBlank();
                    }
                }
            }, onerror: "请输入正确的证件号"
        }).ajaxValidator({
            type: "get",
            url: "service/userMgr.ashx?op=checkidno",
            dataType: 'json',
            success: function(data) {
                try {
                    eval('var json=' + data);

                    if (!$('#IDNoMsg').length) {
                        $('#IDNoTip').after('<div style="float:left;padding-top:4px;" id="IDNoMsg"></div>');
                    }
                    $('#IDNoMsg').html(json.msg);
                    return true;
                } catch (e) {
                    return false;
                }
            },
            error: function() { alert("服务器没有返回数据，可能服务器忙，请重试"); },
            onwait: "正在校验，请稍候..."
        });
        //到职日期验证
        $("#ComeDate").focus(function() {
            WdatePicker({ oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        }).formValidator({ validatorgroup: this.id,
            onshow: "请选择到职日期!",
            onfocus: "请选择到职日期!",
            oncorrect: " "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "到职日期不能为空!" },
            type: "date",
            onerror: "到职日期不能为空!"
        });
        //邮箱验证
        $("#Email").formValidator({ validatorgroup: this.id,
            onshow: " ",
            onfocus: " ",
            oncorrect: " "
        }).regexValidator({
            regexp: "emailOrNull",
            datatype: "enum",
            onerror: "格式不正确"
        });
        //家庭电话验证
        $("#HomeTel").formValidator({ validatorgroup: this.id,
            onshow: "请输入电话！", onfocus: "请输入电话", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#HomeTel").val() == "" && $("#OfficeTel").val() == "" && $("#Mobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入其一电话！"
        });
        //工作电话验证
        $("#OfficeTel").formValidator({ validatorgroup: this.id,
            onshow: "请输入电话！", onfocus: "请输入电话", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#HomeTel").val() == "" && $("#OfficeTel").val() == "" && $("#Mobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入其一电话！"
        });
        //手机号码
        $("#Mobile").formValidator({ validatorgroup: this.id,
            onshow: "请输入手机号！", onfocus: "请输入手机号", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) { if (val == "") return true; return val.isMobile(); }, onerror: "请输入正确的手机号"
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#HomeTel").val() == "" && $("#OfficeTel").val() == "" && $("#Mobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入其一电话！"
        });
        //联系地址验证
        $("#Address").formValidator({ validatorgroup: this.id,
            onshow: "请输入地址", onfocus: "请输入地址", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "头尾不能有空格符!" }, onerror: "地址不能为空!"
        });

    },
    createForm: function() {
        return formCommon.UserManageAddForm('AddUserInfo');
    },
    initEvent: function() {
        var _this = this;
        //提交按钮事件
        $('#aSubmitAddUserAddUserInfo').live('click', function() {
            _this.op = "add";
            _this.save();
        });
        //关闭按钮事件
        $('#aCloseAddUserAddUserInfo').live('click', function() {
            _this.hide();
        });
    },
    getBirthday: function(idcode) {
        var bir = "";
        if (idcode.length == 15) {
            bir += "19" + idcode.substr(6, 2);
            bir += "-";
            bir += idcode.substr(8, 2) + "-" + idcode.substr(10, 2);
        }
        else
            bir += idcode.substr(6, 4) + "-" + idcode.substr(10, 2) + "-" + idcode.substr(12, 2);
        return bir;
    },
    loadRole: function(companyid) {
        var _this = this;
        Chenxin.ajax({
            url: this.actionUrl,
            type: 'get',
            data: { op: 'getdelrolebycompany', companyid: companyid },
            onSuccess: function(data) {
                Chenxin.Fn.createCheckBoxGroup(data.items, 'role', 130, 'td_role');
            }
        });
    },
    createComboList: function() {
        var _this = this;

        //城市
        var city = new Chenxin.UI.Combo({
            containerId: '#divCity',
            tbxWidth: 90,
            inModelType: 'all',
            name: 'CityId',
            txtModelName: 'CityName',
            items: _this.scope.search.comboList[0].items,
            afterLoadItems: function() {
                _this.cityItems = this.items;
            },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    company.clearItems();
                } else {
                    company.param.fatherid = this.getValue();
                    company.reload();
                }
                businessDistrict.clearItems();
                departs.clearItems();
            }
        });

        //公司
        var company = new Chenxin.UI.StructCombo({
            containerId: '#divCompany',
            tbxWidth: 90,
            autoLoad: false,
            inModelType: 'all',
            name: 'CompanyId',
            txtModelName: 'CompanyName',
            param: { op: 'getcompany' },
            afterLoadItems: function() {
                if (this.items.length == 1) {
                    this.addPleaseSelected = false;
                    this.initValue = this.items[0].val;
                    businessDistrict.param.fatherid = this.initValue; //this.defVal;
                    businessDistrict.reload();

                    _this.cmbEmpLevel.param.companyid = this.initValue;
                    _this.cmbEmpLevel.reload();

                    _this.cmbEditPosition.param.companyid = this.initValue;
                    _this.cmbEditPosition.reload();
                    _this.loadRole(this.initValue);
                } else {
                    this.addPleaseSelected = true;
                }
            },
            onSelected: function() {
                if (this.getValue() == this.defValue) {
                    businessDistrict.clearItems();
                    _this.cmbEmpLevel.clearItems();
                    _this.cmbEditPosition.clearItems();
                    $('#td_role').html('');
                } else {
                    businessDistrict.param.fatherid = this.getValue();
                    businessDistrict.reload();

                    _this.cmbEmpLevel.param.companyid = this.getValue();
                    _this.cmbEmpLevel.reload();

                    _this.cmbEditPosition.param.companyid = this.getValue();
                    _this.cmbEditPosition.reload();

                    _this.loadRole(this.getValue());
                }
                departs.clearItems();
            }
        });

        //商圈
        var businessDistrict = new Chenxin.UI.StructCombo({
            containerId: '#divBusinessDistrict',
            tbxWidth: 90,
            colWidth: 120,
            autoLoad: false,
            hasPage: true,
            pageSize: 10,
            param: { op: 'getbusinessdistrict' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    departs.clearItems();
                } else {
                    departs.param.fatherid = this.getValue();
                    departs.reload();
                }
            }
        });
        //部门
        var departs = new Chenxin.UI.StructCombo({
            containerId: '#divDepartId',
            tbxWidth: 90,
            colWidth: 120,
            name: 'DepartId',
            inModelType: 'all',
            txtModelName: 'DepartName',
            autoLoad: false,
            required: true,
            hasPage: true,
            pageSize: 10,
            hasSearch: true,
            param: { op: 'getdeparts' }
        });
        //证件类型
        // this.cmbIDType = new Chenxin.UI.Combo({
        // containerId: '#divIDType',
        // tbxWidth: 90,
        // required: true,
        // items: comboCommon.UserIDType
        // });


        this.cmbIDType = new Chenxin.UI.ParameterCombo({
            containerId: '#divIDType',
            key: 'Custom.CertificateType',
            inModelType: 'txt',
            required: true,
            tbxWidth: 90
        });
        //劳动关系
        this.cmbWork = new Chenxin.UI.ParameterCombo({
            containerId: '#divWork',
            key: 'HR.WorkRelation',
            inModelType: 'txt',
            name:'WorkRelation',
            required: true,
            tbxWidth: 90,
            colNum: 3,
            colWidth: 100
        });
        
        //职级
        this.cmbEmpLevel = new Chenxin.UI.ParameterCombo({
            containerId: '#divEmpLevel',
            name: 'EmpLevel',
            key: 'System.EmpLevel',
            inModelType: 'txt',
            tbxWidth: 90,
            colNum: 3,
            hasPage: true,
            pageSize: 15,
            required: true,
            hasSearch: true,
            autoLoad: false
        });
        
        //职务
        this.cmbEditPosition = new Chenxin.UI.ParameterCombo({
            containerId: '#divEditPosition',
            name: 'Position',
            tbxWidth: 90,
            key: 'System.Position',
            required: true,
            inModelType: 'txt',
            autoLoad: false,
            colNum: 3,
            hasPage: true,
            hasSearch: true,
            pageSize: 15
            /*
            items: _this.scope.search.comboList[7].items,
            afterLoadItems: function() {
            _this.positionItems = this.items;
            }*/
        });
        //教育程度
        this.cmbEducation = new Chenxin.UI.Combo({
            containerId: '#divEducation',
            tbxWidth: 90,
            items: comboCommon.UserEducation
        });

        return [city, company, businessDistrict, departs, this.cmbIDType, this.cmbEmpLevel, this.cmbEditPosition, this.cmbEducation, this.cmbWork];
    },
    saveSucc: function(data) {
        $("#msg_span").html(data);
        $("#div_msg").jqmShow();
        this.reloadGrid();
        this.returndata = data;
    },
    initComponent: function() {
        Chenxin.UI.UserManageAddForm.superclass.initComponent.call(this);
    }
});

/**
*用户修改
*/
Chenxin.UI.UserManageEditForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/userMgr.ashx',
    id: 'jqmEditUserInfo',
    renderTo: 'divjqmEditUserInfo',
    title: '人员编辑',
    jqmWidth: 700,
    initFormValidator: function() {
        var _this = this;
        //用户名验证
        $("#txtName").formValidator({ validatorgroup: this.id,
            onshow: "请输入用户名！", onfocus: "请输入用户名", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "用户名不能为空!" }, onerror: "用户名不能为空!"
        });
        //证件号码验证
        $("#txtIDNO").formValidator({ validatorgroup: this.id,
            onshow: "请输入证件号", onfocus: "请输入证件号", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                var x = _this.findByName('edit_papers');
                if (x) {
                    if (x.getValue() == x.defVal) {
                        return '请先选择证件类型';
                    } else {
                        if (x.getText() == '身份证') {
                            if (val.isIdCardNo()) {
                                $("#txtBirthDay").val(_this.getBirthday(val));
                            }
                            return val.isIdCardNo();
                        } else {
                            return !val.isBlank();
                        }
                    }
                }
                return true;
            }, onerror: "请输入正确的证件号"
        }); /*.ajaxValidator({
            type: "get",
            url: "service/userMgr.ashx?op=checkidno",
			dataType:'json',
            success: function(data) {
				try{
					eval('var json='+data);
					
					if(!$('#txtIDNOMsg').length){
						$('#txtIDNOTip').after('<div style="float:left;padding-top:4px;" id="txtIDNOMsg"></div>');
					}
					$('#txtIDNOMsg').html(json.msg);
					return true;
				}catch(e){
					return false;
				}
            },
            error: function() { alert("服务器没有返回数据，可能服务器忙，请重试"); },
            onwait: "正在校验，请稍候..."
        });*/
        //邮箱验证
        $("#txtEmail").formValidator({ validatorgroup: this.id,
            onshow: " ",
            onfocus: " ",
            oncorrect: " "
        }).regexValidator({
            regexp: "emailOrNull",
            datatype: "enum",
            onerror: "格式不正确"
        });

        //家庭电话验证
        $("#txtHomeTel").formValidator({ validatorgroup: this.id,
            onshow: "请输入电话！", onfocus: "请输入电话", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#txtHomeTel").val() == "" && $("#txtOfficeTel").val() == "" && $("#txtMobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入其一电话！"
        });
        //工作电话验证
        $("#txtOfficeTel").formValidator({ validatorgroup: this.id,
            onshow: "请输入电话！", onfocus: "请输入电话", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#txtHomeTel").val() == "" && $("#txtOfficeTel").val() == "" && $("#txtMobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入其一电话！"
        });
        //手机号码
        $("#txtMobile").formValidator({ validatorgroup: this.id,
            onshow: "请输入手机号！", onfocus: "请输入手机号", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) { if (val == "") return true; return val.isMobile(); }, onerror: "请输入正确的手机号"
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#txtHomeTel").val() == "" && $("#txtOfficeTel").val() == "" && $("#txtMobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入其一电话！"
        });
        //        
        //        //手机验证
        //        $("#txtMobile").formValidator({ validatorgroup: this.id,
        //            onshow: " ",
        //            onfocus: " ",
        //            oncorrect: " "
        //        }).regexValidator({
        //            regexp: "mobileOrNull",
        //            datatype: "enum",
        //            onerror: "格式不正确"
        //        });
        //        //工作电话验证
        //        $("#txtOfficeTel").formValidator({ validatorgroup: this.id,
        //            onshow: " ",
        //            onfocus: "电话号码-分机号",
        //            oncorrect: " "
        //        }).regexValidator({
        //            regexp: "telOrNull",
        //            datatype: "enum",
        //            onerror: "格式不正确"
        //        });
        //        //家庭电话验证
        //        $("#txtHomeTel").formValidator({ validatorgroup: this.id,
        //            onshow: " ",
        //            onfocus: "电话号码-分机号",
        //            oncorrect: " "
        //        }).regexValidator({
        //            regexp: "telOrNull",
        //            datatype: "enum",
        //            onerror: "格式不正确"
        //        });
        //联系地址验证
        $("#txtAddress").formValidator({ validatorgroup: this.id,
            onshow: "请输入地址", onfocus: "请输入地址", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "地址不能为空!" }, onerror: "地址不能为空!"
        });
    },
    createForm: function() {
        return formCommon.UserManageEditForm('EditUserInfo');
    },
    initEvent: function() {
        var _this = this;
        //提交按钮事件
        $('#aEditSubmitEditUserInfo').live('click', function() {
            _this.op = "edit";
            _this.save();
        });
        //关闭按钮事件
        $('#aEditCloseEditUserInfo').live('click', function() {
            _this.hide();
        });
    },
    getBirthday: function(idcode) {
        var bir = "";
        if (idcode.length == 15) {
            bir += "19" + idcode.substr(6, 2);
            bir += "-";
            bir += idcode.substr(8, 2) + "-" + idcode.substr(10, 2);
        }
        else
            bir += idcode.substr(6, 4) + "-" + idcode.substr(10, 2) + "-" + idcode.substr(12, 2);
        return bir;
    },
    createComboList: function() {
        var _this = this;

        //教育程度
        var cmbEducation = new Chenxin.UI.Combo({
            containerId: '#edit_ed',
            tbxWidth: 90,
            items: comboCommon.UserEducation
        });
        //证件类型
        // var cmbIDType = new Chenxin.UI.Combo({
        // containerId: '#edit_papers',
        // tbxWidth: 90,
        // required: true,
        // items: comboCommon.UserIDType
        // });

        var cmbIDType = new Chenxin.UI.ParameterCombo({
            containerId: '#edit_papers',
            key: 'Custom.CertificateType',
            inModelType: 'txt',
            required: true,
            tbxWidth: 90
        });

        var cmbWork = new Chenxin.UI.ParameterCombo({
            containerId: '#edit_work',
            key: 'HR.WorkRelation',
            inModelType: 'txt',
            name:'WorkRelation',
            required: true,
            tbxWidth: 90,
            colNum: 3,
            colWidth:100
        });

        //职级
        var cmbEmpLevel = new Chenxin.UI.ParameterCombo({
            containerId: '#edit_divEmpLevel',
            name: 'EmpLevel',
            key: 'System.EmpLevel',
            inModelType: 'txt',
            tbxWidth: 90,
            colNum: 4,
            hasPage: true,
            hasSearch: true,
            pageSize: 40,
            required: true,
            autoLoad: false
        });
        //职务
        var cmbEditPosition = new Chenxin.UI.ParameterCombo({
            containerId: '#edit_divEditPosition',
            name: 'Position',
            tbxWidth: 90,
            colNum: 3,
            hasPage: true,
            pageSize: 15,
            required: true,
            hasSearch: true,
            inModelType: 'txt',
            key: 'System.Position',
            autoLoad: false
        });
        //城市
        this.city = new Chenxin.UI.StructCombo({
            containerId: '#edit_divCity',
            tbxWidth: 90,
            name: 'BelongCityId',
            inModelType: 'all',
            txtModelName: 'BelongCityName',
            param: { op: 'getcity' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    _this.company.clearItems();
                } else {
                    _this.company.param.fatherid = this.getValue();
                    _this.company.reload();
                }
                _this.departs.clearItems();
            }
        });

        //公司
        this.company = new Chenxin.UI.StructCombo({
            containerId: '#edit_divCompany',
            tbxWidth: 90,
            name: 'BelongCompanyId',
            inModelType: 'all',
            txtModelName: 'BelongCompanyName',
            autoLoad: false,
            param: { op: 'getcompany' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    _this.departs.clearItems();

                    cmbEmpLevel.clearItems();
                    cmbEditPosition.clearItems();
                } else {
                    _this.departs.param.fatherid = this.getValue();
                    _this.departs.reload();


                    cmbEmpLevel.param.companyid = this.getValue();
                    cmbEmpLevel.reload();


                    cmbEditPosition.param.companyid = this.getValue();
                    cmbEditPosition.reload();
                }
                _this.departs.clearItems();
            }
        });

        //部门
        this.departs = new Chenxin.UI.StructCombo({
            containerId: '#edit_divDepartId',
            tbxWidth: 90,
            colWidth: 120,
            hasSearch: true,
            name: 'BelongDepartId',
            inModelType: 'all',
            txtModelName: 'BelongDepart',
            colNum: 2,
            hasPage: true,
            pageSize: 10,
            autoLoad: false,
            required: true,
            param: { op: 'getcompanydeparts' }
        });

        return [cmbEducation, cmbIDType, cmbEmpLevel, cmbEditPosition, this.city, this.company, this.departs,cmbWork];
    },
    saveSucc: function() {
        this.reloadGrid();
    },
    initComponent: function() {
        Chenxin.UI.UserManageEditForm.superclass.initComponent.call(this);
    }
});

/**
*人事变动
*/
Chenxin.UI.UserChgPersonnelForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/userMgr.ashx',
    id: 'jqmChgPersonnel',
    renderTo: 'divjqmChgPersonnel',
    title: '人事变动',
    jqmWidth: 600,
    initFormValidator: function() {
        var _this = this;

        //变动日期
        $("#txtTransTimeChgPer").focus(function() {
            WdatePicker({ oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        }).formValidator({ validatorgroup: this.id,
            onshow: "请输入变动日期!",
            onfocus: "请输入变动日期!",
            oncorrect: " "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "变动日期不能为空!" },
            type: "date",
            onerror: "变动日期不能为空!"
        });

    },
    createForm: function() {
        return formCommon.UserChgPersonnelForm('ChgPer');
    },
    initEvent: function() {
        var _this = this;
        //提交按钮事件
        $('#aChangeSubmitChgPer').live('click', function() {
            _this.op = "change";
            _this.save();
        });
        //关闭按钮事件
        $('#aChangeCloseChgPer').live('click', function() {
            _this.hide();
        });
    },
    createComboList: function() {
        var _this = this;

        //城市
        var city = new Chenxin.UI.StructCombo({
            containerId: '#divCityChgPer',
            tbxWidth: 90,
            inModelType: 'none',
            param: { op: 'getcity' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    company.clearItems();
                } else {
                    company.param.fatherid = this.getValue();
                    company.reload();
                }
                businessDistrict.clearItems();
                departs.clearItems();
            }
        });

        //公司
        var company = new Chenxin.UI.StructCombo({
            containerId: '#divCompanyChgPer',
            tbxWidth: 90,
            autoLoad: false,
            inModelType: 'none',
            param: { op: 'getcompany' },
            afterLoadItems: function() {
                if (this.items.length == 1) {
                    this.addPleaseSelected = false;
                    this.initValue = this.items[0].val;
                    businessDistrict.param.fatherid = this.initValue; //this.defVal;
                    businessDistrict.reload();
					
					
                    cmbEmpLevel.param.companyid = this.initValue; //this.defVal;
                    cmbEmpLevel.reload();
					
					
                    cmbEditPosition.param.companyid = this.initValue; //this.defVal;
                    cmbEditPosition.reload();
                } else {
                    this.addPleaseSelected = true;
                }
            },
            onSelected: function() {
                if (this.getValue() == this.defValue) {
                    businessDistrict.clearItems();
                    cmbEmpLevel.clearItems();
                    cmbEditPosition.clearItems();
                } else {
                    businessDistrict.param.fatherid = this.getValue();
                    businessDistrict.reload();
					
					
                    cmbEmpLevel.param.companyid = this.getValue(); //this.defVal;
                    cmbEmpLevel.reload();
					
					
                    cmbEditPosition.param.companyid = this.getValue(); //this.defVal;
                    cmbEditPosition.reload();
                }
                departs.clearItems();
            }
        });

        //商圈
        var businessDistrict = new Chenxin.UI.StructCombo({
            containerId: '#divBusinessDistrictChgPer',
            tbxWidth: 90,
            colWidth: 120,
            autoLoad: false,
            inModelType: 'none',
            param: { op: 'getbusinessdistrict' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    departs.clearItems();
                } else {
                    departs.param.fatherid = this.getValue();
                    departs.reload();
                }
            }
        });

        //部门
        var departs = new Chenxin.UI.StructCombo({
            containerId: '#divDepartChgPer',
            name: 'DepartId',
            tbxWidth: 90,
            colWidth: 120,
            hasPage: true,
            pageSize: 10,
            autoLoad: false,
            required: false,
            param: { op: 'getdeparts' }
        });

        //变动类型
        var cmbTransType = new Chenxin.UI.Combo({
            containerId: '#divTransTypeChgPer',
            inModelType: 'all',
            txtModelName: 'TransType',
            name: 'TransTypeId',
            tbxWidth: 90,
            items: comboCommon.TransType1,
            required: true,
            onSelected: function() {
                if (this.getValue() == 2 || this.getValue() == 3) {
                    $("#tr_zd").show();
                    $("#tr_zw").show();
                    cmbEmpLevel.required = true;
                    cmbEditPosition.required = true;
                    $("#tr_city").hide();
                    $("#tr_company").hide();
                    $("#tr_businessdistrict").hide();
                    $("#tr_depart").hide();
                    departs.required = false;
                }
                else if (this.getValue() == 4) {
                    $("#tr_city").show();
                    $("#tr_company").show();
                    $("#tr_businessdistrict").show();
                    $("#tr_depart").show();
                    departs.required = true;
                    $("#tr_zd").show();
                    $("#tr_zw").show();
                    cmbEmpLevel.required = true;
                    cmbEditPosition.required = true;
                }
                else if (this.getValue() == 5 || this.getValue() == 6||this.getValue()==8) {
                    $("#tr_zd").show();
                    $("#tr_zw").show();
                    cmbEmpLevel.required = true;
                    cmbEditPosition.required = true;
                    $("#tr_city").show();
                    $("#tr_company").show();
                    $("#tr_businessdistrict").show();
                    $("#tr_depart").show();
                    departs.required = true;
                }
                else {
                    $("#tr_zd").hide();
                    $("#tr_zw").hide();
                    cmbEmpLevel.required = false;
                    cmbEditPosition.required = false;
                    $("#tr_city").hide();
                    $("#tr_company").hide();
                    $("#tr_businessdistrict").hide();
                    $("#tr_depart").hide();
                    departs.required = false;
                }

                if (this.getText().indexOf("调动") >= 0||this.getText()=="到职")
                    departs.required = true;
                else
                    departs.required = false;
            }
        });
        //职级
        var cmbEmpLevel = new Chenxin.UI.ParameterCombo({
            containerId: '#divEmpLevelChgPer',
            name: 'Level',
            key: 'System.EmpLevel',
            inModelType: 'txt',
            tbxWidth: 90,
			colWidth:100,
            colNum: 4,
            hasPage: true,
            pageSize: 20,
            required: false,
			hasSearch:true,
			autoLoad:false
        });
        //职务
        var cmbEditPosition = new Chenxin.UI.ParameterCombo({
            containerId: '#divEditPositionChgPer',
            inModelType: 'txt',
            key: 'System.Position',
            name: 'Position',
            tbxWidth: 90,
            colNum: 4,
			colWidth:100,
            hasPage: true,
            pageSize: 20,
			hasSearch:true,
            required: false,
			autoLoad:false

        });
        return [city, company, businessDistrict, departs, cmbTransType, cmbEmpLevel, cmbEditPosition];
    },
    saveSucc: function() {
        this.reloadGrid();
    },
    initComponent: function() {
        Chenxin.UI.UserChgPersonnelForm.superclass.initComponent.call(this);
    }
});

/**
*员工职权设定
*/
Chenxin.UI.UserTermsForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/userMgr.ashx',
    id: 'jqmUserTerms',
    renderTo: 'divjqmUserTerms',
    title: '职权设定',
    jqmWidth: 600,
    autoHide: false,
	createGrid:function(){
		return new Chenxin.UI.Pagination({
			actionUrl: 'service/userMgr.ashx?op=pageShow&stype=terms',
			renderTo:'scope_table',
			id:'scopetable',
			pageSize: 10,
			autoLoad:false
		});
	},
    initFormValidator: function() {
        var _this = this;

        //开始时间
        $("#terms_dateUserTerms").focus(function() {
            WdatePicker({ oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        }).formValidator({ validatorgroup: this.id,
            onshow: "请输入开始时间!",
            onfocus: "请输入开始时间!",
            oncorrect: " "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "开始时间不能为空!" },
            type: "date",
            onerror: "开始时间不能为空!"
        });
    },
    createForm: function() {
        return formCommon.UserTermsForm('UserTerms');
    },
    initEvent: function() {
        var _this = this;

        //新增职权按钮事件
        $('#btn_addshowUserTerms').live('click', function() {
            $("#div_TermsShow").show();
            $("#btn_addUserTerms").show();
            $(this).hide();
        });

		$('#btn_terms_del').live('click',function(){
			var levelDate=$('#inp_levedate').val();
			_this.del(_this.currentId+"&endtime=" + levelDate,'DelTerms');
		});
        //删除按钮事件
        $('.btndel_Terms').live('click', function() {
            if (this.name == "0") {
                alert("该条记录为隶属信息，不可删除！");
                return;
            }
			$(this).after('<input type="text" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});" style="width: 80px;" class="inputbox_n" id="inp_levedate" readonly="readonly"><input type="button" value="确定" id="btn_terms_del">');
			_this.currentId=this.name;
			$(this).hide();
        });

        //提交按钮事件
        $('#btn_addUserTerms').live('click', function() {
            _this.op = "addterms";
            _this.save();
        });


    },
    createComboList: function() {
        var _this = this;

        //城市
        var city = new Chenxin.UI.StructCombo({
            containerId: '#divCityUserTerms',
            tbxWidth: 90,
			inModelType:'none',
            param: { op: 'getcity' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    company.clearItems();
                } else {
                    company.param.fatherid = this.getValue();
                    company.reload();
                }
                businessDistrict.clearItems();
                departs.clearItems();
            }
        });

        //公司
        var company = new Chenxin.UI.StructCombo({
            containerId: '#divCompanyUserTerms',
            tbxWidth: 90,
            autoLoad: false,
            param: { op: 'getcompany' },
			inModelType:'none',
            afterLoadItems: function() {
                if (this.items.length == 1) {
                    this.addPleaseSelected = false;
                    this.initValue = this.items[0].val;
                    businessDistrict.param.fatherid = this.initValue; //this.defVal;
                    businessDistrict.reload();
                } else {
                    this.addPleaseSelected = true;
                }
            },
            onSelected: function() {
                if (this.getValue() == this.defValue) {
                    businessDistrict.clearItems();
                } else {
                    businessDistrict.param.fatherid = this.getValue();
                    businessDistrict.reload();
                }
                departs.clearItems();
            }
        });

        //商圈
        var businessDistrict = new Chenxin.UI.StructCombo({
            containerId: '#divBusinessDistrictUserTerms',
            tbxWidth: 90,
            colWidth: 120,
            autoLoad: false,
			inModelType:'none',
            param: { op: 'getbusinessdistrict' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    departs.clearItems();
                } else {
                    departs.param.fatherid = this.getValue();
                    departs.reload();
                }
            }
        });

        //部门
        var departs = new Chenxin.UI.StructCombo({
            containerId: '#divDepartUserTerms',
			inModelType:'all',
			name:'DepartId',
			txtModelName:'DepartName',
			tbxWidth: 90,
			colWidth: 120,
            autoLoad: false,
            required: true,
            param: { op: 'getdeparts' }
        });


        //职权
        var cmbtermsType = new Chenxin.UI.Combo({
            containerId: '#terms_sel',
            tbxWidth: 90,
			name:'RoleType',
            required: true,
            items: comboCommon.authority1
        });

        return [city, company, businessDistrict, departs, cmbtermsType];
    },
    initComponent: function() {
        Chenxin.UI.UserTermsForm.superclass.initComponent.call(this);
		this.grid=this.createGrid();
    }
});

/**
*虚帐号
*/
Chenxin.UI.UserVirtualForm=Chenxin.extend(Chenxin.UI.FormCommon,{
	actionUrl:'service/userMgr.ashx',
	id:'jqmUserVirtual',
	renderTo:'divjqmUserVirtual',
	title:'添加虚帐号',
	jqmWidth:600,
	initFormValidator:function(){
        var _this=this;
        
        //姓名验证
        $("#Virtual_name").formValidator({ validatorgroup:this.id,
            onshow: "请输入姓名！", onfocus: "请输入姓名", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "姓名不能为空!" }, onerror: "姓名不能为空!"
        });                
	},
	createForm:function(){
		return formCommon.UserVirtualForm('UserVirtual');
	},
	initEvent:function(){
		var _this=this;
		
		//提交按钮事件
		$('#aVirtualSubmitUserVirtual').live('click',function(){
		    _this.op="virtual";
			_this.save();
		});
		//关闭按钮事件
		$('#aVirtualCloseUserVirtual').live('click',function(){
			_this.hide();
		});
	},
	createComboList:function(){	
	    var _this=this;
	    
        //城市
        var city = new Chenxin.UI.StructCombo({
            containerId: '#divCityUserVirtual',
            tbxWidth: 90,
			name:'CityId',
			txtModelName:'CityName',
			inModelType:'all',
            param: { op: 'getcity' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    company.clearItems();
                } else {
                    company.param.fatherid = this.getValue();
                    company.reload();
                }
                businessDistrict.clearItems();
                departs.clearItems();
            }
        });
		
		//公司
		var company=new Chenxin.UI.StructCombo({
		    containerId: '#divCompanyUserVirtual',
		    tbxWidth:90,
			autoLoad:false,
			inModelType:'all',
			name:'CompanyId',
			txtModelName:'CompanyName',
			param:{op:'getcompany'},
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					this.initValue=this.items[0].val;
					businessDistrict.param.fatherid=this.initValue;//this.defVal;
					businessDistrict.reload();
				}else{
					this.addPleaseSelected=true;						
				}
			},
			onSelected:function(){
				if(this.getValue()==this.defValue){
					businessDistrict.clearItems();
				}else{
					businessDistrict.param.fatherid=this.getValue();
					businessDistrict.reload();
				}
				departs.clearItems();
			}
		});
		
		//商圈
		var businessDistrict=new Chenxin.UI.StructCombo({
		    containerId: '#divBusinessDistrictUserVirtual',
		    tbxWidth:90,
			autoLoad:false,
			inModelType:'none',
			param:{op:'getbusinessdistrict'},
			onSelected:function(){
				if(this.getValue()==this.defVal){
					departs.clearItems();
				}else{
					departs.param.fatherid=this.getValue();
					departs.reload();
				}
			}
		});
		
		//部门
		var departs=new Chenxin.UI.StructCombo({
		    containerId: '#divDepartUserVirtual',
		    tbxWidth:90,
			inModelType:'all',
			name:'DepartId',
			txtModelName:'DepartName',
		    autoLoad: false,
			required :true,
			param:{op:'getdeparts'}
		});	

		return [city,company,businessDistrict,departs];
	},
	
	initComponent:function(){
		Chenxin.UI.UserVirtualForm.superclass.initComponent.call(this);
	}
});

/**
*职务与职权设定
*/
Chenxin.UI.UserPosTermsForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/userMgr.ashx',
    id: 'jqmPosTerms',
    renderTo: 'divjqmPosTerms',
    title: '职务与职权设定',
    jqmWidth: 600,
    autoHide: false,
    createForm: function() {
        return formCommon.UserPosTermsForm('PosTerms');
    },
    afterGetFormJson: function(data) {
        Chenxin.apply(this.additionalParam, data);
    },
    initEvent: function() {
        var _this = this;

        //查询职权职务
        $("#pt_search").live("click", function() {
            var jsonCondition = _this.SearchPosTerms.getParamJson();
            if (jsonCondition.CompanyID == "请选择")
                delete jsonCondition.CompanyID;
            if (jsonCondition.PostName == "请选择")
                delete jsonCondition.PostName;
            _this.PosTermsGrid.reload(jsonCondition);

        });

        //提交按钮事件
        $('#btnPosTerms_add').live('click', function() {
            _this.op = "addpt";
            _this.save();
        });
        //关闭按钮事件
        $('#btnPosTerms_hid').live('click', function() {
            _this.hide();
        });
        //删除职权
        $('#btndel_PosTerms').live('click', function() {
            _this.del(this.name, "delpt");
        });

        _this.SearchPosTerms = new Chenxin.UI.PosTermsSearch({
            scope: _this,
            afterGetParamJson: function(data) {
                data.CompanyID = _this.cmbcitycearch._val;
                data.PostName = _this.cmbposterms._txt;
                data.op = "pageShow";
                data.stype = "pt";
            }
        });
    },
    afterDelSucc:function(){
        $("#pt_search").click();
    },
    createComboList: function() {
        var _this = this;

        //获取全部公司
        Chenxin.ajax({
            type: "post",
            dataType: "json",
            url: 'service/userMgr.ashx',
            data: { op: "GetAllCompany" },
            async: false,
            onSuccess: function(data) {
                _this.rtnitems = data;
            }
        });


        //公司-Search
        this.cmbcitycearch = new Chenxin.UI.Combo({
            containerId: '#divCompanyPosTerms',
            tbxWidth: 90,
            items: eval("([{txt:'请选择',val:'请选择'}" + _this.rtnitems + "])")
        });

        //职权-Search
        this.cmbposterms = new Chenxin.UI.Combo({
            containerId: '#divPosTerms',
            tbxWidth: 90,
            inModelType: 'txt',
            items: comboCommon.authority1
        });

        //职权-Add
        this.cmbposterms_a = new Chenxin.UI.Combo({
            containerId: '#divPosTerms_a',
            tbxWidth: 90,
            required: true,
            inModelType: 'txt',
            items: comboCommon.authority1
        });

        //公司-Add
        this.cmbcityadd = new Chenxin.UI.Combo({
            containerId: '#divCompanyPosTerms_a',
            tbxWidth: 90,
            items: comboCommon.authority1,
            required: true,
            onSelected: function() {
                _this.cmbposition.param.companyid = this.getValue();
                _this.cmbposition.reload();
            }
        });

        //职务
        this.cmbposition = new Chenxin.UI.Combo({
            actionUrl: 'service/userMgr.ashx',
            param: { op: 'GetTerms' },
            tbxWidth: 150,
            containerId: '#divPositionPosTerms_a',
            showMode: 'multi',
            inModelType: 'txt',
            required: true,
            colNum: 3,
            hasPage: true,
            pageSize: 15
        });
        return [this.cmbcitycearch, this.cmbposterms, this.cmbposterms_a, this.cmbcityadd, this.cmbposition];
    },
    initComponent: function() {
        Chenxin.UI.UserPosTermsForm.superclass.initComponent.call(this);
    }
});

$(document).ready(function() {
    var favorMgr = new Chenxin.UI.userManager();
    $("#div_msg").jqm().jqDrag('.jqDrag');
    //继续添加该部门人员
    $("#msg_add").live("click",function(){
        $("#div_msg").jqmHide();        
        favorMgr.jqmUserManageAddForm.show();
        $("#divjqmAddUserInfo :text").val("");
        favorMgr.jqmUserManageAddForm.cmbIDType.reset();
        favorMgr.jqmUserManageAddForm.cmbEmpLevel.resetValue();
        favorMgr.jqmUserManageAddForm.cmbEditPosition.resetValue();
        favorMgr.jqmUserManageAddForm.cmbEducation.reset();
    });
    //继续添加其他部门人员
    $("#msg_close").live("click",function(){
         $("#div_msg").jqmHide();
        $("#aAddUser").click();
    });
    //确认 关闭
    $("#msg_confirm").live("click",function(){
        $("#div_msg").jqmHide();
    });
});